home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWUtil.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  11.4 KB  |  403 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWUtil.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWUTIL_H
  13. #include "FWUtil.h"
  14. #endif
  15.  
  16. #ifndef FWFRAME_H
  17. #include "FWFrame.h"
  18. #endif
  19.  
  20. // ----- OS Includes -----
  21.  
  22. #ifndef FWPOINT_H
  23. #include "FWPoint.h"
  24. #endif
  25.  
  26. #ifndef FWGDEV_H
  27. #include "FWGDev.h"
  28. #endif
  29.  
  30. #ifndef FWRECT_H
  31. #include "FWRect.h"
  32. #endif
  33.  
  34. #ifndef FWGC_H
  35. #include "FWGC.h"
  36. #endif
  37.  
  38. #ifndef FWGRGLOB_H
  39. #include "FWGrGlob.h"
  40. #endif
  41.  
  42. #ifndef FWODGEOM_H
  43. #include "FWODGeom.h"
  44. #endif
  45.  
  46. #ifndef FWFXMATH_H
  47. #include "FWFxMath.h"
  48. #endif
  49.  
  50. // ----- OpenDoc Includes -----
  51.  
  52. #ifndef SOM_ODShape_xh
  53. #include <Shape.xh>
  54. #endif
  55.  
  56. #ifndef SOM_ODCanvas_xh
  57. #include <Canvas.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODWindow_xh
  61. #include <Window.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODTransform_xh
  65. #include <Trnsform.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODFacet_xh
  69. #include <Facet.xh>
  70. #endif
  71.  
  72. // ----- Macintosh Includes -----
  73.  
  74. #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
  75. #include <Drag.h>
  76. #endif
  77.  
  78. // ----- Windows Includes -----
  79.  
  80. #if defined(FW_BUILD_WIN) && !defined(_INC_WINDOWS)
  81. #include <windows.h>
  82. #endif
  83.  
  84. //========================================================================================
  85. // Runtime Informations
  86. //========================================================================================
  87.  
  88. #if FW_LIB_EXPORT_PRAGMAS
  89. #pragma lib_export on
  90. #endif
  91.  
  92. #ifdef FW_BUILD_MAC
  93. #pragma segment framework
  94. #endif
  95.  
  96. //========================================================================================
  97. // Globales Methods
  98. //========================================================================================
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // ::XorShape
  102. //----------------------------------------------------------------------------------------
  103.  
  104. FW_FUNC_ATTR ODShape* XorShape(Environment* ev, ODShape* a, ODShape* b)
  105. {
  106.     ODShape* result = a->Copy(ev);
  107.     result->Union(ev, b);
  108.     
  109.     FW_CAcquiredODShape aqIntersect(a->Copy(ev));
  110.     aqIntersect->Intersect(ev, b);
  111.     
  112.     result->Subtract(ev, aqIntersect);
  113.     
  114.     return result;
  115. }
  116.  
  117. //----------------------------------------------------------------------------------------
  118. // ::FW_Beep
  119. //----------------------------------------------------------------------------------------
  120.  
  121. FW_FUNC_ATTR void FW_Beep()
  122. {
  123. #ifdef FW_BUILD_MAC
  124.     ::SysBeep(10);
  125. #endif
  126. #ifdef FW_BUILD_WIN
  127.     ::MessageBeep(-1);
  128. #endif
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. // ::CenterRectOnScreen
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_FUNC_ATTR void CenterRectOnScreen(FW_SPlatformRect& aRect, FW_Boolean horizontally, FW_Boolean vertically, FW_Boolean forDialog)
  136. {
  137. #ifdef FW_BUILD_MAC
  138.     short newSize = 0;
  139.     FW_SPlatformPoint rectSize, screenSize;
  140.  
  141.     ::SetPt(&rectSize, aRect.right - aRect.left, aRect.bottom - aRect.top);
  142.     ::SetPt(&screenSize, FW_QDGlobals.screenBits.bounds.right - FW_QDGlobals.screenBits.bounds.left,
  143.                         FW_QDGlobals.screenBits.bounds.bottom - FW_QDGlobals.screenBits.bounds.top);
  144.     screenSize.v -= GetMBarHeight();
  145.  
  146.     // Calculate screen size minus menu bar 
  147.     if (horizontally)
  148.         aRect.left = (screenSize.h - rectSize.h) / 2;
  149.     if (vertically)
  150.         if (forDialog)
  151.         {
  152.             newSize = (screenSize.v - rectSize.v) / 5;
  153.             aRect.top = (short)(FW_Maximum(newSize, 10) + GetMBarHeight());
  154.         }
  155.         else
  156.             aRect.top = (screenSize.v - rectSize.v) / 2;
  157.     
  158.     aRect.bottom = aRect.top + rectSize.v;
  159.     aRect.right = aRect.left + rectSize.h;
  160. #endif
  161.  
  162. #ifdef FW_BUILD_WIN
  163. FW_UNUSED(aRect);
  164. FW_UNUSED(horizontally);
  165. FW_UNUSED(vertically);
  166. FW_UNUSED(forDialog);
  167.     FW_DEBUG_MESSAGE("Not Yet Implemented");
  168. #endif
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. // FW_GetMainScreenBounds
  173. //----------------------------------------------------------------------------------------
  174.  
  175. void FW_GetMainScreenBounds(FW_CRect& bounds)
  176. {
  177. #ifdef FW_BUILD_MAC
  178.     FW_CFixed menuBarHeight = FW_IntToFixed(LMGetMBarHeight());
  179.     bounds.Set(FW_kFixed0, 
  180.                 menuBarHeight,
  181.                    FW_IntToFixed(FW_QDGlobals.screenBits.bounds.right),
  182.                    menuBarHeight + FW_IntToFixed(FW_QDGlobals.screenBits.bounds.bottom));
  183. #endif
  184.     
  185. #ifdef FW_BUILD_WIN
  186.     FW_SPlatformRect scr;
  187.     ::GetWindowRect(::GetDesktopWindow(), &scr);
  188.     bounds = scr;
  189. #endif
  190. }
  191.  
  192. //========================================================================================
  193. //    class FW_CFacetContext
  194. //========================================================================================
  195.  
  196. //----------------------------------------------------------------------------------------
  197. // FW_CFacetContext::FW_CFacetContext
  198. //----------------------------------------------------------------------------------------
  199.  
  200. FW_CFacetContext::FW_CFacetContext(Environment* ev, ODFacet *facet, ODShape* invalidShape) :
  201.     FW_CGraphicContext(ev),
  202.     fFacet(facet)
  203. {
  204.     FW_ASSERT(facet != NULL);
  205.     
  206.     FW_CAcquiredODTransform aqContentTransform = facet->AcquireContentTransform(ev, NULL);
  207.     
  208.     // InitGraphicContext expect clip shape in content coordinates
  209.     FW_CAcquiredODTransform aqInternalTransform = fFacet->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
  210.     FW_CAcquiredODShape aqClipShape(FW_CopyAndRelease(ev, fFacet->AcquireAggregateClipShape(ev, NULL)));
  211.     aqClipShape->InverseTransform(ev, aqInternalTransform);
  212.     
  213.     if (invalidShape != NULL)
  214.         aqClipShape->Intersect(ev, invalidShape);
  215.  
  216.     InitGraphicContext(FW_CFacetPartInfo::GetFacetGraphicDevice(ev, fFacet),
  217.                         aqContentTransform,
  218.                         aqClipShape);
  219. }
  220.  
  221. //----------------------------------------------------------------------------------------
  222. //    FW_CFacetContext::~FW_CFacetContext
  223. //----------------------------------------------------------------------------------------
  224.  
  225. FW_CFacetContext::~FW_CFacetContext()
  226. {
  227. }
  228.  
  229. //========================================================================================
  230. //    class FW_CWindowContext
  231. //========================================================================================
  232.  
  233. //----------------------------------------------------------------------------------------
  234. //    FW_CWindowContext::FW_CWindowContext
  235. //----------------------------------------------------------------------------------------
  236.  
  237. FW_CWindowContext::FW_CWindowContext(Environment* ev, ODFacet* odFacet) :
  238.     FW_CGraphicContext(ev),
  239.     fTempDevice(NULL),
  240.     fODWindow(NULL)
  241. {
  242.     InitWindowContext(ev, odFacet->GetWindow(ev));
  243. }
  244.  
  245. //----------------------------------------------------------------------------------------
  246. //    FW_CWindowContext::FW_CWindowContext
  247. //----------------------------------------------------------------------------------------
  248.  
  249. FW_CWindowContext::FW_CWindowContext(Environment* ev, ODWindow *odWindow) :
  250.     FW_CGraphicContext(ev),
  251.     fTempDevice(NULL),
  252.     fODWindow(NULL)
  253. {
  254.     InitWindowContext(ev, odWindow);
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    FW_CWindowContext::InitWindowContext
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void FW_CWindowContext::InitWindowContext(Environment* ev, ODWindow *odWindow)
  262. {
  263.     FW_ASSERT(odWindow != NULL);
  264.     fODWindow = odWindow;
  265.     fODWindow->Acquire(ev);
  266.     
  267.     ODFacet *facet = odWindow->GetRootFacet(ev);
  268.  
  269. #ifdef FW_BUILD_MAC
  270.     FW_CRect rect(odWindow->GetPlatformWindow(ev)->portRect);
  271. #endif
  272. #ifdef FW_BUILD_WIN
  273.     FW_SPlatformRect clientRect;
  274.     ::GetClientRect(odWindow->GetPlatformWindow(ev), &clientRect);
  275.     FW_CRect rect(clientRect);
  276. #endif
  277.  
  278.     FW_CAcquiredODShape aqClipShape = ::FW_NewODShape(ev, rect);
  279.  
  280. /*
  281.     [HLX] there is a problem trying to reuse the graphic device of the root frame. 
  282.     First of all if the graphic device has a fContext, it should be suspended. Also
  283.     now that we are running static part I don't know what the effect is. We need to 
  284.     look at that. Might be able to put it back when we move the graphic to a SOM DLL.
  285.     
  286.     FW_CGraphicDevice* device = FW_CFacetPartInfo::GetFacetGraphicDevice(ev, facet);
  287.     if (device == NULL)
  288.     {
  289.         fTempDevice = new FW_CGraphicDevice(ev, facet->GetCanvas(ev));
  290.         device = fTempDevice;
  291.     }
  292.  
  293.     InitGraphicContext(device,
  294.                         NULL,
  295.                         aqClipShape);
  296. */
  297.     
  298.     fTempDevice = new FW_CGraphicDevice(ev, facet->GetCanvas(ev));
  299.     
  300.     InitGraphicContext(fTempDevice,
  301.                         NULL,
  302.                         aqClipShape);
  303. }
  304.  
  305. //----------------------------------------------------------------------------------------
  306. //    FW_CWindowContext::~FW_CWindowContext
  307. //----------------------------------------------------------------------------------------
  308.  
  309. FW_CWindowContext::~FW_CWindowContext()
  310. {
  311.     if (fODWindow)
  312.         fODWindow->Release(somGetGlobalEnvironment());
  313.         
  314.     if (fTempDevice)
  315.         fTempDevice->Release();
  316. }
  317.  
  318. //========================================================================================
  319. //    class FW_CPlatformGraphicContext
  320. //========================================================================================
  321.  
  322. //----------------------------------------------------------------------------------------
  323. // FW_CPlatformGraphicContext::FW_CPlatformGraphicContext
  324. //----------------------------------------------------------------------------------------
  325.  
  326. FW_CPlatformGraphicContext::FW_CPlatformGraphicContext(Environment* ev, ODFacet *facet, ODShape* invalidShape) :
  327.     FW_CGraphicContext(ev),
  328.     fFacet(facet)
  329. #ifdef FW_BUILD_MAC
  330.     ,fMacPort(NULL)
  331. #endif
  332. {
  333.     FW_ASSERT(facet != NULL);
  334.  
  335.     // InitGraphicContext expect clip shape in content coordinates
  336.     FW_CAcquiredODTransform aqInternalTransform = fFacet->GetFrame(ev)->AcquireInternalTransform(ev, NULL);
  337.     FW_CAcquiredODShape aqClipShape(FW_CopyAndRelease(ev, fFacet->AcquireAggregateClipShape(ev, NULL)));
  338.     aqClipShape->InverseTransform(ev, aqInternalTransform);
  339.     
  340.     if (invalidShape != NULL)
  341.         aqClipShape->Intersect(ev, invalidShape);
  342.  
  343.     InitGraphicContext(FW_CFacetPartInfo::GetFacetGraphicDevice(ev, fFacet),
  344.                         NULL,
  345.                         aqClipShape);
  346.                         
  347. #ifdef FW_BUILD_MAC
  348.     FW_CAcquiredODTransform aqContentTransform = facet->AcquireContentTransform(ev, NULL);
  349.     FW_CPoint origin(FW_kZeroPoint);
  350.     origin.Transform(ev, aqContentTransform);
  351.     
  352.     ::GetPort(&fMacPort);    
  353.     fMacOrigin.h = fMacPort->portRect.left;
  354.     fMacOrigin.v = fMacPort->portRect.top;
  355.  
  356.     ::SetOrigin(- origin.x.AsInt(), - origin.y.AsInt());
  357. #endif
  358.  
  359. #ifdef FW_BUILD_WIN
  360. #endif
  361. }
  362.  
  363. //----------------------------------------------------------------------------------------
  364. // FW_CPlatformGraphicContext::~FW_CPlatformGraphicContext
  365. //----------------------------------------------------------------------------------------
  366.  
  367. FW_CPlatformGraphicContext::~FW_CPlatformGraphicContext()
  368. {
  369. #ifdef FW_BUILD_MAC
  370.     if (fMacPort != NULL)
  371.     {
  372.         GrafPtr port;
  373.         ::GetPort(&port);    
  374.         ::SetPort(fMacPort);    
  375.         ::SetOrigin(-fMacOrigin.h, -fMacOrigin.v);
  376.         ::SetPort(port);
  377.     }
  378. #endif
  379. }
  380.  
  381. //========================================================================================
  382. //    Storage Unit Utilities
  383. //========================================================================================
  384.  
  385. //----------------------------------------------------------------------------------------
  386. // FW_SUAddPropValue
  387. //----------------------------------------------------------------------------------------
  388.  
  389. void FW_FUNC_ATTR FW_SUAddPropValue(Environment* ev, ODStorageUnit* su, ODPropertyName prop, ODValueType val)
  390. {
  391.     if (!su->Exists(ev, prop, NULL, 0))
  392.     {
  393.         su->AddProperty(ev, prop)->AddValue(ev, val);
  394.     }
  395.     else
  396.     {
  397.         su->Focus(ev, prop, kODPosUndefined, NULL, 0, kODPosUndefined);
  398.         if (!su->Exists(ev, prop, val, 0))
  399.             su->AddValue(ev, val);
  400.     }
  401. }
  402.  
  403.